package com.zhuqi.redis.list;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * @author : ZhuQi
 * @version : 时间:2022/1/10 11:20 版本:
 */
@Component
@Slf4j
public class ProService {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    /**
     * 队列名
     */
    private final String workerQueueName = "ORDER_QUEUE";

    /**
     * 测试内容:
     */
    public void test() throws Exception {
        ListOperations<String, String> stringStringListOperations = stringRedisTemplate.opsForList();
        int i = 0;
        while (true) {
            ++i;
            String name = "订单号";
            stringStringListOperations.leftPush(workerQueueName, "订单号" + i);
            log.info("生产线程生产了消息:{}", "订单号" + i);
            try {
                TimeUnit.SECONDS.sleep(5);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
